 package co.edu.usbcali.ai.ga;

import java.util.ArrayList;
import java.util.List;

public class BinaryCromosomType extends CromosomType {

	public BinaryCromosomType(int size){
		setSizeType(CromosomType.FIXED_SIZE);
		setType(CromosomType.HOMOGENE);
		setSize(size);
		List<BinaryGeneType> list=new ArrayList<BinaryGeneType>(size);
		list.add(new BinaryGeneType());
		setGeneTypes(list);
		setFullPopulation((long)Math.pow(2,size));
	}
	
	public float evaluate(ICromosom p_cromosom){
		long res=Long.parseLong(getFenotype(p_cromosom));
		return (float)(res*res);
	}

	public String getFenotype(ICromosom p_cromosom) {
		String chain="";
		for(int con=0;con<getSize();con++){
			chain+=((SimpleCromosom)p_cromosom).get(con).getValue();
		}
		int res=Integer.parseInt(chain,2);
		return Integer.toString(res);
	}
	
	public long fullPopulation(){
		return (long)Math.pow(2,getSize());
	}

}
